package treasurer;

import home.HomePage;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.BKSubsidiary;
import controllers.PE;

public class PropertiesAndEquipmentList extends WebPage {

	public PropertiesAndEquipmentList () throws SQLException, IOException
	{
		Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		
		add(new BookmarkablePageLink("home", TreasurerHome.class));
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		add(new BookmarkablePageLink("addRecord", BookKeepersSubsidiary.class));
		
		Form form = new Form("PeListForm");
		
		List<PE> list = (List<PE>)sqlMap.queryForList("PE.getAll");
		
		ListView eachRecord = new ListView("eachRecord", list) {
			private static final long serialVersionUID = 1L;
			
			protected void populateItem(ListItem item) {
				final PE pe = (PE) item.getModelObject();
				
				item.add(new Label("date", pe.getDateOfPurchase()));
				item.add(new Label("item", pe.getItem()));
				item.add(new Label("cost", Float.toString(pe.getCost())));
				item.add(new Label("propertyNo", pe.getPropertyNo()));
				item.add(new Label("sourceOfFunding", pe.getSourceOfFunding()));
				item.add(new Label("condition", pe.getCondition()));
				item.add(new Label("status", pe.getStatus()));
			}
		};
		form.add(eachRecord);
		add(form);
		
	}
}
